package com.jcf.springboot.common.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@MapperScan({"com.jcf.springboot.mapper"})
public class CinemaConfig implements WebMvcConfigurer{
    /**
     * 逻辑删除插件
     */
    @Bean
    public ISqlInjector sqlInjector() {
        return new LogicSqlInjector();
    }

    @Value("${spring.application.name}")
    private String moduleName;

  /**
   * 分页插件
   * */
  @Bean
  public PaginationInterceptor paginationInterceptor(){
      return new PaginationInterceptor();
  }
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //设置允许跨域请求的域名
                .allowedOrigins("*")
                //这里：是否允许证书 不再默认开启
                .allowCredentials(true)
                //设置允许的方法
                .allowedMethods("*")
                //跨域允许时间
                .maxAge(3600);
    }

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
      System.out.println("modelname" + moduleName);
      System.out.println(System.getProperty("user.dir"));
        /*registry.addResourceHandler("/image/actorPhoto/**")
                .addResourceLocations("file:E:\\graduationProject\\cinema-system-parent\\service\\service-cinema\\src\\main\\resources\\static\\image\\actorPhoto\\");
        registry.addResourceHandler("/image/filmPoster/**")
                .addResourceLocations("file:E:\\graduationProject\\cinema-system-parent\\service\\service-cinema\\src\\main\\resources\\static\\image\\filmPoster" +
                        "\\");
        registry.addResourceHandler("/image/member/**")
                .addResourceLocations("file:E:\\graduationProject\\cinema-system-parent\\service\\service-cinema\\src\\main\\resources\\static\\image\\member" +
                        "\\");
        registry.addResourceHandler("/image/notice/**")
                .addResourceLocations("file:E:\\graduationProject\\cinema-system-parent\\service\\service-cinema\\image\\notice\\" +
                        "\\");
        registry.addResourceHandler("/image/directorPhoto/**")
                .addResourceLocations("file:E:\\graduationProject\\cinema-system-parent\\service\\service-cinema\\image\\directorPhoto\\" +
                        "\\");
        registry.addResourceHandler("/image/actorPhoto/**")
                .addResourceLocations("file:E:\\graduationProject\\cinema-system-parent\\service\\service-cinema\\image\\actorPhoto\\" +
                        "\\");
        registry.addResourceHandler("/image/stills/**")
                .addResourceLocations("file:E:\\graduationProject\\cinema-system-parent\\service\\service-cinema\\image\\stills\\" +
                        "\\");
        registry.addResourceHandler("/image/filmPoster/**")
                .addResourceLocations("file:E:\\graduationProject\\cinema-system-parent\\service\\service-cinema\\image\\filmPoster\\" +
                        "\\");
        registry.addResourceHandler("/image/member/**")
                .addResourceLocations("file:E:\\graduationProject\\cinema-system-parent\\service\\service-cinema\\image\\member\\" +
                        "\\");*/
     /* registry.addResourceHandler("/image/**")
       .addResourceLocations("file:D:\\jichaofan\\project\\cinema-system-parent\\service\\service-cinema\\image\\");*/
      registry.addResourceHandler("/image/**")
       .addResourceLocations("file:" + System.getProperty("user.dir") + "/" + moduleName + "/image/")
       .addResourceLocations("file:" + System.getProperty("user.dir") + "/" + "/image/");
//      这里细节是，我将path打印出来后，地址最后是没有 "/" 的，没有的话就是在当前目录以及下面的目录中找，但是如果有 “/” 的话，就是在当前目录下面的目录中找资源
    }

}
